-- tests scene
local Stage11 = 0x01
local Stage12 = 0x02
local Stage13 = 0x03
local Stage14 = 0x04
local Stage21 = 0x05
local Stage22 = 0x06
local Stage23 = 0x07
local Stage24 = 0x08
local Stage31 = 0x09
local Stage32 = 0x10
local Stage33 = 0x11
local Stage34 = 0x12
local Stage41 = 0x13
local Stage42 = 0x14
local Stage43 = 0x15
local Stage44 = 0x16

local UI_Name =
{
    [0] = "1-1",
    "1-2",
    "1-3",
    "1-4",
    "2-1",
    "2-2",
    "2-3",
    "2-4",
    "3-1",
    "3-2",
    "3-3",
    "3-4",
    "4-1",
    "4-2",
    "4-3",
    "4-4",
}

local layer = nil

local function initWithLayer()

    -- 按钮回调函数
    local function menuCallback(tag)
        if tag ~= -1 then
            Play_Effect(sme_Click)
            Create_HLWS_Scene(tag)
        else
            Play_Effect(sme_ClickError)
            Func_DataStatis(DS_ClickNil)
        end
    end

    -- 创建一个主菜单
    local MainMenu = CCMenu:create()
    -- 主菜单大小
    MainMenu:setContentSize(CCSizeMake(DWinSizeWidth,  DWinSizeHeight))
    -- 设置坐标
    MainMenu:setPosition(0, 0)
    -- 添加至主菜单层
    layer:addChild(MainMenu, 2)
    
    local index = 1
    local _bpx = 100
    local _bpy = 700
    local _itemH = 150
    local _itemW = 150
    local _cuts = 4
    for index, labelName in pairs(UI_Name) do
        -- 坐标
        local idx = (index)
        local pos = gdccp(_bpx + idx%_cuts * _itemW, _bpy - math.floor(idx/4) * _itemH)
        
        local num = GameNumbers:new(vNumberStage)
        num:addLayer(layer, 5)
        num:setNumber(labelName)
        num:setPosition(pos)
        
        -- 获得关卡积分与过关积分,查看是否过关
        local isenable = false
        local score = GetStageDatas(index-1)
        local _StageInfos = StageInfos_HLWS[index-1]
        if _StageInfos == nil or score >= _StageInfos[PScore] then
            isenable = true
        end
        
        local _inv_f = math.floor(index/4)
        if not isenable then
            _inv_f = _inv_f + 4
            --显示锁头
            local spLocks = CCSprite:createWithSpriteFrameName("ModeLock.png")
            spLocks:setPosition(ccp(pos.x + gdv(45), pos.y-gdv(50)))
            layer:addChild(spLocks,3)
        end
        local btnItem = GFunc_CreateButtonP(string.format("FBG_icon_0%d.png", _inv_f + 1), menuCallback, 1.2)
        btnItem:setPosition(pos)
        btnItem:setPosition(pos)
        
        if isenable then
            -- 禁用按钮
            MainMenu:addChild(btnItem, index, index)
        else
            --num:setColor(ccc3(100,100,100))
            MainMenu:addChild(btnItem)
        end
    end
    
    
    
    -- 背景
    local _bgSpr = nil
    _bgSpr = CCSprite:createWithSpriteFrameName(s_Space_bg)
    _bgSpr:setPosition(gdccp(DWinSizeWidth/2, DWinSizeHeight/2))
    layer:addChild(_bgSpr)
    _bgSpr = CCSprite:createWithSpriteFrameName(s_Space_bgHead)
    _bgSpr:setPosition(gdccp(DWinSizeWidth/2, 960-32))
    layer:addChild(_bgSpr, 9)
    
    
    local function onTouchEnded(x, y)
    end

    local function onTouch(eventType, x, y)
    end
    
    --print(layer)
    layer:setTouchEnabled(true)
    layer:registerScriptTouchHandler(onTouch)

    return layer
end

--------------------------------
-- Click And Move Test
--------------------------------
function Create_HLWS_Select_Scene()
    local scene = CCScene:create()
    layer = CCLayer:create()

    initWithLayer()

    scene:addChild(layer)
    scene:addChild(CreateBackMenuItem())

    return scene, UI_Begin
end
